/**
 * 专题页面
 */
var App = require("../libs/network/mvr.js");
var Imports = require("../libs/utils/imports.js");
var Template = require("../libs/plugins/art-template.js");
var XData = require("../libs/gamepump/xdata.js");
var NativeApp = require("../libs/phonegap/native-bridge.js");
var Url = require("../libs/utils/url.js");
var Stat = require("../libs/utils/stat.js");
var conTpl = Imports("text!../page-layout/album/container.html");
var cardTpl = Imports("text!../page-layout/album/list.html");

var container = $(conTpl);
$("#dt-content").append(container);

container.on('tap', '.dt-zt-div', function(e){
    var url = $(e.currentTarget).attr('data-url');
    console.log('go: ' + url);
    if(url){
        var newId= url.substring(url.indexOf("=")+1,url.length);
        Stat.addActionStat("detail_news","zt",newId);
        Url.gotoPage(url);
        e.preventDefault();
        return false;
    }
});

App.addModule("CardList",
    App.Model.extend({
        'key' : "201", //数据协议keycode
        'private' : 1, //是否走专属通道传递参数
        'params' : "pcount=4&adposid=435&sort=time" //专属参数定义
    }),
    App.View.extend({
        //容器标识
        container: container,
        childSum:0,
        haveloadCount:0,
        //视图渲染回调函数定义
        render: function(dlist){
            var that=this;
            var tpl = Template(cardTpl);
            var imgsDom = $(tpl({"dataList": dlist}));
            this.childSum += dlist.length;
            imgsDom.find("img").on("load", function() {pageImgLoadEnded(that);});
            this.container.append(imgsDom);
        }
    })
);
function pageImgLoadEnded(mview){
    if(++mview.haveloadCount === mview.childSum){
        window.slipjs.refresh();
        App.Requester.enable();
    }
}
App.Requester.init({
    container: container,
    //oneTime:true,
    afterLoad: function(){
        App.Requester.disable();
    }
});
App.Requester.tigger();